<form action="/sales/ajaxbutton?op=updateGoodsState"  method="post" name="batchendorderST" id="batchendorderST">
<style type="text/css">
	.st1 tbody  tr td{padding:3px 3px;};
</style>
<input type="hidden" name="dataid" value="{{$dataid}}" />
<input type="hidden" name="allcost_price" id="allcost_price" value="{{$info['cost_price']}}" />
<table cellpadding="0" cellspacing="0" border="1" class="stdtable st1">
 <thead>
  <tr class="child_subject tit">
    <th class="head1">NO.</th>
    <th class="head1">商品编号</th>
    <th class="head1">商品名称</th>
    <th class="head1">仓库</th>
    <th class="head1">库存数</th>
     <th class="head1">盘点数</th>
    <th class="head1">成本价</th>
    <th class="head1">清仓折后价</th>
    <!--<th class="head1">滞销损耗金额</th>-->
    </td>
  </tr>
 </thead>
  {{foreach from=$needstore item=li key=key}}
  <tr>
    <td>{{$key+1}}</td>
    <td><a href="/product/productlist?other={{$li.sku}}&filtertype=skuc" target="_blank" style="text-decoration:none;color:black;">{{$li.sku}}</a></td>
    <td>{{$li.goods_name|getstr:22:0}}</td>
    <td>{{$li.storagename}}</td>
    <td>{{$li.stock}}</td>
     <td>{{$li.confirmstock}}</td>
    <td>{{$li.cost_price}}</td>
    <td>
    <input type="hidden" name="dataid" value="{{$dataid}}" />
    <input name="goodsid_{{$li.goods_id}}" class="inputClass" cost_price="{{$li.cost_price}}" type="text" style="width:40px;padding:4px 4px;" value="{{$li.discount}}" /></td>
<!--    <td> <input name="unsold_goodsid_{{$li.goods_id}}" class="soldinputClass" salecost_price="{{$li.cost_price}}" type="text" style="width:40px;padding:4px 4px;" value="{{$li.discount}}" /></td>-->
  </tr>
  {{/foreach}}
  <tr class="child_subject">
    <td colspan="9" valign="middle" align="center" bgcolor="#FFFFFF" style="position:relative;line-height:28px">
    	填写清仓折扣：
         <select name="discount" id="discount"  style="width:100px;" onchange="setDiscount()" >
            <option value="0">请选择折扣</option>
            <option value="100">无折扣</option>
            <option value="70">70%</option>
            <option value="50">50%</option>
            <option value="30">30%</option>
        </select>
    	折
    	(例：75折则75)总价值({{$info.cost_price}}), 折后价值:(<span id="cost_price_span"></span>)     
    	</td>
  </tr>
 <!-- <tr class="child_subject">
    <td colspan="9" valign="middle" align="center" bgcolor="#FFFFFF" style="position:relative;line-height:28px">
    	填写滞销损耗承担比例：
         <select name="unsolddiscount" id="unsolddiscount"  style="width:100px;" onchange="setunsoldDiscount()" >
            <option value="0">请选择比例</option>
            <option value="100">全部承担</option>
            <option value="70">承担70%</option>
            <option value="50">承担50%</option>
            <option value="30">承担30%</option>
        </select>
    	对于开发人员认定的死库，报废或清仓后不再计算库息，报废的损失由开发人员和公司共同承担     
    	</td>
  </tr>-->
</table>
<div align="center" style="padding-top:10px;">
  <button id="btn" type="button" onclick="checkFormData()" class="submit radius2">确认清仓</button>
</div>  
</form>
<script language="javascript">
	function setDiscount(){
		if($("#discount").val()==''){
			alert("请填写清仓折扣");
		}else{
			var discount=$("#discount").val();
			$(".inputClass").each(function(){
				var cost_price=$(this).attr("cost_price");
				$(this).val(parseInt(cost_price*discount/100));
			});
		}
		$("#cost_price_span").html(parseInt($("#allcost_price").val()*discount/100));		
	}
	function setunsoldDiscount(){
		if($("#unsolddiscount").val()==''){
			alert("填写滞销损耗均摊比例");
		}else{
			var unsolddiscount=$("#unsolddiscount").val();
			$(".soldinputClass").each(function(){
				var cost_price=$(this).attr("salecost_price");
				$(this).val(parseInt(cost_price*unsolddiscount/100));
			});
		}
	}
	function checkFormData(){
		var error=0;
		$(".inputClass").each(function(){
			var discountprice=$(this).val();
			if(discountprice==''){
				
				error=1;
			}
		});
		if(error==0){
			$("#batchendorderST").submit();
		}else{
			alert("清仓价格不能为空，请先设置好所有商品的清仓折后价格再提交吧");
		}
	}
</script>
